'''
Created on 01/05/2011

@author: Adam
'''

import logging

from flask import render_template

from application.models import Mappers
from application.decorators import admin_required, template_init
import application.utils as Util

from google.appengine.ext.deferred import defer
from test_apikeys import apiUserId, apiKey

@admin_required
@template_init
def TestApi():
	logging.debug('test debug')
	logging.info('test info')
	api = Util.startApi()
	auth = api.auth(userID=apiUserId, apiKey=apiKey)
	result = auth.account.Characters()
	return render_template('cron/TestApi.html', characters=result.characters)

@admin_required
@template_init
def AllianceList():
	api = Util.startApi()
	result = api.eve.AllianceList()
	mapper = Mappers.AllianceMapper('cron')
	alliances = []
	for record in result.alliances:
		alliances.append(record)
	defer(mapper.run, alliances, _queue='cron', _countdown=5)
	return render_template('cron/default.html', cronMessage='Alliance List scheduled for update.')

@admin_required
@template_init
def Sovereignty():
	api = Util.startApi()
	result = api.map.Sovereignty()
	mapper = Mappers.SolarSystemSovMapper('cron')
	solarSystems = []
	for record in result.solarSystems:
		solarSystems.append(record)
	defer(mapper.run, solarSystems, _queue="cron", _countdown=5)
	return render_template('cron/default.html', cronMessage='Solar systems sovereignty scheduled for update.')
